function [dirname]=findUniqueDirname(startdir, foldername)
%this will search for a folder name in a directory, if it exists then it
%increments some post fix counters, create that unique folder and return
%its name

direxists=1;
dircount=0;

while(direxists==1)

    dircount=dircount+1;

    curdirname=[startdir '/' foldername num2str(dircount)];

    if(exist(curdirname,'dir')==0)
        mkdir(curdirname);
        direxists=0;
    end

end


dirname=curdirname;



end